package cn.bluethink.eguan.core.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;

import cn.bluethink.eguan.model.core.EgBag;
import cn.bluethink.eguan.model.core.EgCheckStatus;
import cn.bluethink.eguan.model.core.EgFaction;
import cn.bluethink.eguan.model.core.EgTavern;
import cn.bluethink.eguan.model.core.EgUser;

/**
 * 驿馆实体类
 * 
 * @title 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.1.0
 * @describe
 * @author liuxn
 * @date 2018年10月13日
 */
@Table(name = "eg_tavern")
public class EgTavernEntity implements Serializable {
    private static final long serialVersionUID = -846587850197368049L;

    @Id
    private Long egid;

    private Long fid;

    private String name;

    private String icon;

    private String des;

    private Long uid;

    private Long bagid;

    private Date utime;

    private Date ctime;

    @Column(name = "check_status")
    private Integer checkStatus;

    public EgTavernEntity() {

    }

    public EgTavernEntity(EgTavern tavern, boolean bcreate) {
        this.egid = tavern.getId();
        this.fid = tavern.getFaction() == null ? null : tavern.getFaction().getId();
        this.name = tavern.getName();
        this.icon = tavern.getIcon();
        this.des = tavern.getDes() == null ? "" : tavern.getDes().trim();
        this.checkStatus = tavern.getCheckStatus();

        if (bcreate) {
            this.uid = tavern.getUser() == null ? null : this.uid;
            this.bagid = tavern.getBag().getId();
            this.checkStatus = tavern.getCheckStatus() == null ? EgCheckStatus.STATUS_PENDING : tavern.getCheckStatus();
        }
    }

    /**
     * 创建驿管
     * 
     * @return
     */
    public EgTavern createTavern() {
        EgTavern tavern = new EgTavern(egid, name, icon);
        tavern.setDes(des);
        tavern.setUser(new EgUser(uid, null, null));
        tavern.setBag(new EgBag(bagid, null));
        fid = (fid == null) ? 0L : fid;
        EgFaction faction = new EgFaction(fid, null, null);
        tavern.setFaction(faction);
        tavern.setuTime(utime);
        tavern.setCheckStatus(checkStatus);
        return tavern;
    }

    public Long getEgid() {
        return egid;
    }

    public void setEgid(Long egid) {
        this.egid = egid;
    }

    public Long getFid() {
        return fid;
    }

    public void setFid(Long fid) {
        this.fid = fid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getDes() {
        return des;
    }

    public void setDes(String des) {
        this.des = des;
    }

    public Long getUid() {
        return uid;
    }

    public void setUid(Long uid) {
        this.uid = uid;
    }

    public Long getBagid() {
        return bagid;
    }

    public void setBagid(Long bagid) {
        this.bagid = bagid;
    }

    public Date getUtime() {
        return utime;
    }

    public void setUtime(Date utime) {
        this.utime = utime;
    }

    public Date getCtime() {
        return ctime;
    }

    public void setCtime(Date ctime) {
        this.ctime = ctime;
    }

    public Integer getCheckStatus() {
        return checkStatus;
    }

    public void setCheckStatus(Integer checkStatus) {
        this.checkStatus = checkStatus;
    }

}
